<%@ page import="service.impl.petServiceImpl" %>
<%@ page import="entity.Pet" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: deng
  Date: 2021/3/14
  Time: 13:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%String path=request.getContextPath();%>
<%String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<html>
  <head>
    <title>宠物管理</title>
    <script src="jquery-1.12.4.js"></script>
  </head>
  <body>
  <table border="0" align="center" id="table">
    <tr >
      <td>品种:</td>
      <td> <select  name="breed1">
        <option value="---请选择---">---请选择---</option>
        <option value="狗">狗</option>
        <option value="猫">猫</option>
        <option value="鸟">鸟</option>
        <option value="兔">兔</option>
      </select></td>
      <td><input type="button" id="select" value="查询"/></td>
      <td><a href="addPet.jsp">新增宠物</a></td>
    </tr>
  </table>
  <table border="1" align="center" id="table2">
    <tr>
      <td height="19">宠物名称</td>
      <td height="19">出身日期</td>
      <td height="19">性别</td>
    </tr>
    <%
      if(null!=session.getAttribute("select")){
        List<Pet> list=(List<Pet>)session.getAttribute("select");
        request.setAttribute("pet",list);
      }else {
        petServiceImpl ps = new petServiceImpl();
        List<Pet> ase = ps.SelectPetinAll();
        request.setAttribute("pet", ase);
      }
    %>
    <c:forEach var="item" items="${pet}">
      <tr>
        <td height="19">${item.name}</td>
        <td height="19">${item.birthday}</td>
        <td height="19">${item.sex}</td>
      </tr>
    </c:forEach>
  </table>
  <script type="text/javascript">

    function odd(){
      $("#table2 tr:even:not(tr:first)").css("background-color","lightskyblue")
      $("#table2 tr:first").css({"background-color":"darkgray"},{"font-size":"20px"});
    }
    odd();

    $(document).ready(function () {
      $("#select").click(function () {
        var select=$("select").find(":selected").val();
        switch (select) {
          case "狗":
            location.href="<%=basePath%>select?lei=狗";
            break;
          case "猫":
            location.href="<%=basePath%>select?lei=猫";
            break;
          case "鸟":
            location.href="<%=basePath%>select?lei=鸟";
            break;
          case "兔":
            location.href="<%=basePath%>select?lei=兔";
            break;
          default:
          <%
          session.removeAttribute("select");
          %>
            location.reload();
        }
      })
    })
  </script>
  </body>
</html>
